3D Graphics Programming with QuickDraw 3D 1.5.4

Previous | QD3D Book | Overview | Chapter Contents | Next

Writing Public Draw Context Methods

As you've seen, the draw context structure (of type TQADrawContext ) contains function pointers to the public draw context methods supported by your drawing engine. These methods are called whenever an application calls one of the public functions provided by QuickDraw 3D RAVE. For example, when an application calls the QADrawPoint function for a draw context associated with your drawing engine, your engine's TQADrawPoint method (pointed to by the drawPoint field) is called. The TQADrawPoint method is declared like this:

typedef void (*TQADrawPoint) (
                     const TQADrawContext *drawContext,
                     const TQAVGouraud *v);

A draw context structure is passed as the first parameter to all the public draw context methods you need to define. This allows your methods to find the private data associated with the draw context (which is pointed to by the drawPrivate field).

Notice that the function prototype for a point-drawing method passes the draw context as a const parameter. This indicates that your method should not alter any of the fields of the draw context structure passed to it. Only three draw context methods (namely TQASetInt , TQASetFloat , and TQASetPtr ) are allowed to alter the draw context.

Listing 10 shows a sample definition for a point-drawing method.

Listing 10 A TQADrawPoint method

void MyDrawPoint (const TQADrawContext *drawContext, const TQAVGouraud *v)
{
    MyPrivateData               *myData;    /*our actual private data type*/

    /*Cast generic drawPrivate pointer to our actual private data type.*/
    myData = (MyPrivateData *) drawContext->drawPrivate;
    
    /*Call our z-buffered pixel drawing function with xyz and argb, and
      also pass it the current zfunction, which is stored in the private draw
      context data structure. Note that this isn't a complete implementation!
      (We should be using kQATag_Width, for example.)*/

    MyDrawPixelWithZ(v->x, v->y, v->z, v->a, v->r, v->g, v->b,
                                        myData->stateVariable[kQATag_ZFunction]);
}

See "Public Draw Context Methods" for complete information on the public draw context methods your drawing engine must define.

Once you've defined the necessary public draw context methods, you need to insert pointers to those methods into a draw context structure. You accomplish this step in your TQADrawPrivateNew method, described in the next section.


© 1997 Apple Computer, Inc.

Previous | QD3D Book | Overview | Chapter Contents | Next